#ifndef COMBOBOX_H
#define COMBOBOX_H

#include "element.h"
#include <QVector>
#include <functional>
#include <QSharedPointer>

class QLUISHARED_EXPORT ComboBox : public Element
{
    Q_OBJECT
public:
    ComboBox();

    /*********************************************************************
     *                    Copying
     * *******************************************************************/
public:
    virtual bool copyFrom(const Element *e) override;
    virtual Element* clone() const override;

    /*********************************************************************
     *                              Data
     * *******************************************************************/
    Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
    Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText)
public:
    typedef std::function<QString(int index)> ItemModelFun;
    typedef std::function<int(void)> ItemModelCount;

    void addItem(const QString &item);
    void setModel(ItemModelFun model, int max);
    void setModel(ItemModelFun model, ItemModelCount count);

    void setMaxCount(int max);
    int maxCount() const;

    void setCurrentIndex(int index);
    int currentIndex() const;

    void setCurrentText(const QString &text);
    QString currentText() const;

private:
    QVector<QString> items_;
    ItemModelFun model_fun_;
    ItemModelCount max_count_;
    int current_index_;
    QString current_text_;

    /*********************************************************************
     *                    paint
     * *******************************************************************/
public:
    virtual QRect sizeHint() const override;

protected:
    virtual void paintEvent() override;


    /*********************************************************************
     *                    event
     * *******************************************************************/
public slots:
    void onKeyEvent(int key, int value);

signals:
    void currentIndexChanged(int index);


    /*********************************************************************
     *                              Load
     * *******************************************************************/
public:
    virtual bool loadXML(QXmlStreamReader &root, Context *context, SkipType skip=SkipAfterLoaded) override;


    /*********************************************************************
     *                    MetaInfo
     * *******************************************************************/
public:
    virtual QString getSignalSignature(const QString& name) const override;

};

#endif // COMBOBOX_H
